package com.lanou.renrenxin.tools;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by dllo on 16/3/8.
 */
public class PreferenceManager {
    public static final String PREFERENCE_NAME = "saveInfo";
    private static PreferenceManager mPreferenceManager;
    private static SharedPreferences mSharedPreferences;
    private static SharedPreferences.Editor editor;

    private String SHARED_KEY_SETTING_NOTIFICATION = "shared_key_setting_notification";
    private String SHARED_KEY_SETTING_SOUND = "shared_key_setting_sound";
    private String SHARED_KEY_SETTING_VIBRATE = "shared_key_setting_vibrate";
    private String SHARED_KEY_SETTING_SPEAKER = "shared_key_setting_speaker";

    public PreferenceManager(Context cxt) {
        mSharedPreferences = cxt.getSharedPreferences(PREFERENCE_NAME,Context.MODE_PRIVATE);
        editor = mSharedPreferences.edit();
    }

    public static synchronized void init(Context cxt){
        if (mPreferenceManager == null){
            mPreferenceManager = new PreferenceManager(cxt);
        }
    }
    /**
     * 单例模式，获取instance实例
     *
     * @param cxt
     * @return
     */
    public synchronized static PreferenceManager getInstance(){
        if (mPreferenceManager == null){
            throw new RuntimeException("please init first");
        }
        return mPreferenceManager;
    }
    public void setSettingMsgNotification(boolean paramBoolean){
        editor.putBoolean(SHARED_KEY_SETTING_NOTIFICATION,paramBoolean);
        editor.commit();
    }
    public boolean getSettingMsgNotification(){
        return mSharedPreferences.getBoolean(SHARED_KEY_SETTING_NOTIFICATION,true);
    }
    public void setSettingMsgSound(boolean paramBoolean){
        editor.putBoolean(SHARED_KEY_SETTING_SOUND,paramBoolean);
        editor.commit();
    }
    public boolean getSettingMsgSound() {
        return mSharedPreferences.getBoolean(SHARED_KEY_SETTING_SOUND, true);
    }
    public void setSettingMsgVibrate(boolean paramBoolean) {
        editor.putBoolean(SHARED_KEY_SETTING_VIBRATE, paramBoolean);
        editor.commit();
    }

    public boolean getSettingMsgVibrate() {
        return mSharedPreferences.getBoolean(SHARED_KEY_SETTING_VIBRATE, true);
    }

    public void setSettingMsgSpeaker(boolean paramBoolean) {
        editor.putBoolean(SHARED_KEY_SETTING_SPEAKER, paramBoolean);
        editor.commit();
    }

    public boolean getSettingMsgSpeaker() {
        return mSharedPreferences.getBoolean(SHARED_KEY_SETTING_SPEAKER, true);
    }
}
